﻿using MongoDB.Driver;
using MongoDB.Driver.GridFS;

namespace PicShare.Data
{
    public class MongoDbContext<T> where T : class
    {
        public MongoCollection<T> MongoCollection { get; private set; }
        public MongoDatabase Db { get; set; }

        public readonly MongoGridFS GridFileSystem;
      
        public MongoDbContext()
        {
            //const string connectionString = "mongodb://borkata84:manastira21@ds053808.mongolab.com:53808/testdb";
            const string connectionString = "mongodb://localhost";
            var client = new MongoClient(connectionString);
            var server = client.GetServer();
            this.Db = server.GetDatabase("picsharedb");
            this.MongoCollection = Db.GetCollection<T>(typeof(T).Name.ToLower() + "s");
            this.GridFileSystem = this.Db.GridFS;
        }
    }
}
